package chapter6;
import java.util.Scanner;

/****************************************************************
 * Author：icynlau
 * Description: 电话 字母转数字   复用了exc4_15的代码
 * Date:2021/4/4
 * ***************************************************************
 */
public class exc6_21 {
	
	public static void main(String[] args) {
		
		Scanner input=new Scanner(System.in);
		
		System.out.print("Enter the string:  ");
		String s=input.nextLine();
		String ans="";  //转化后字符串
		
		for(int i=0;i<s.length();i++) {
			
			if(s.charAt(i)>='a' && s.charAt(i)<='z' || s.charAt(i)>='A' && s.charAt(i)<='Z' ) {
				char ch=Character.toUpperCase(s.charAt(i));
				ans+=(char)((int)'0'+getNumber(ch));
			}else {
				ans+=s.charAt(i);
			}
			
		}
		
		System.out.print(ans);
		
	}
	
	public static int getNumber(char uppercaseLetter) {
		
		int ret=0;
		
		if(uppercaseLetter>='A'&&uppercaseLetter<='C') {
			ret=2;
		}else if(uppercaseLetter>='D'&&uppercaseLetter<='F') {
			ret=3;
		}else if(uppercaseLetter>='G'&&uppercaseLetter<='I') {
			ret=4;
		}else if(uppercaseLetter>='J'&&uppercaseLetter<='L') {
			ret=5;
		}else if(uppercaseLetter>='M'&&uppercaseLetter<='O') {
			ret=6;
		}else if(uppercaseLetter>='P'&&uppercaseLetter<='S') {
			ret=7;
		}else if(uppercaseLetter>='T'&&uppercaseLetter<='V') {
			ret=8;
		}else if(uppercaseLetter>='W'&&uppercaseLetter<='Z') {
			ret=9;
		}
		
		return ret;
		
	}

}
